43d4af71eaa44e1d980f2e4e5fcd8c074d084464,opennms-webapp/src/main/java/org/opennms/web/controller/admin/thresholds/ThresholdController.java,ThresholdController,gotoNewThreshold,#String#,129

Before Change


        ThresholdingConfigFactory configFactory=ThresholdingConfigFactory.getInstance();
        
        Group group=configFactory.getGroup(groupName);
        Threshold threshold=new Threshold();
        //Set the two default values which need to be set for the UI to work properly
        threshold.setDsType("node");
        threshold.setType("high"); 
	threshold.setTrigger(1); //Default to 1 - 0 will give an error, so we may as well be helpful
        
        //We're assuming that adding a threshold puts it at the end of the current list (i.e. that the Group implementation
        // uses a simple List structure, probably ArrayList).  We can be a bit cleverer later on and check though, so we should
        int thresholdIndex=group.getThresholdCount();
        
        group.addThreshold(threshold);
        
        //Double check the guess index, just in case:
        if(threshold!=group.getThreshold(thresholdIndex)) {

After Change


        
        //Check if last threshold has dsName. If not, we assume that is a new definition (not saved yet on thresholds.xml)
        Threshold threshold = null;
        if (thresholdIndex > 0) {
            threshold=group.getThreshold(thresholdIndex-1);
            if (threshold.getDsName() == null || threshold.getDsName().equals("")) {
            	thresholdIndex--;
            } else {
            	threshold = null;
            }
        }
        
        // create a new threshold object
        if (threshold == null) {
            threshold=new Threshold();
            //Set the two default values which need to be set for the UI to work properly
            threshold.setDsType("node");
            threshold.setType("high"); 
            threshold.setTrigger(1); //Default to 1 - 0 will give an error, so we may as well be helpful
            group.addThreshold(threshold);
        }
        
        //Double check the guess index, just in case: